import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import path from 'path'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import px2rem from 'postcss-pxtorem'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        AutoImport({
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        }),
    ],
    css: {
        preprocessorOptions: {
            less: {
                charset: false,
                additionalData: '@import "./src/assets/global.less";',
                JavascriptEnable: true,
            }
        },
        loaderOptions: {
            postcss: {
                plugins: [
                    px2rem({
                        remUnit: 192
                    })
                ]
            }
        }
    },
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url)),
            '~': fileURLToPath(new URL('./', import.meta.url)),
            '@assets': path.join(__dirname, 'src/assets')
        },
    },
    server: {
        port: 3000,
        host: true,
        proxy: {
            '/exam-client': {
                target: 'http://219.155.7.244:28888/',
                changeOrigin: true,
            },
            '/XXxxXX': {
                target: 'http://219.155.7.244:21683/',
                changeOrigin: true,
            },
            '/webStatic': {
                target: 'http://219.155.7.244:21683/',
                changeOrigin: true,
            }
        },
    },
})
